<template>
  <div class="wrapper">
    <div class="options">
      <el-checkbox-group v-model="dates" :max="3" @change="changeDates">
        <el-checkbox label="0">成立以来</el-checkbox>
        <el-checkbox label="1">近三月</el-checkbox>
        <el-checkbox label="2">近六月</el-checkbox>
        <el-checkbox label="3">近一年</el-checkbox>
        <el-checkbox label="4">近二年</el-checkbox>
        <el-checkbox label="5">近三年</el-checkbox>
      </el-checkbox-group>
    </div>
    <div class="mt40">
      <el-table
        v-if="tableData.length > 0"
        v-loading="loading"
        :data="tableData"
        style="width: 100%; margin-bottom: 20px"
        row-key="id"
        stripe
      >
        <el-table-column
          prop="bd"
          label="标的"
          align="left"
          width="220"
          :show-overflow-tooltip="true"
        >
          <template v-slot="scope">
            <el-button type="text" style="text-align: left">
              <span>{{ scope.row.pdCode }}</span>
              <div>{{ scope.row.pdNm }}</div>
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="astTpNm"
          label="资产类别"
          align="center"
          width="220"
        >
        </el-table-column>
        <el-table-column
          prop="estbDt"
          label="成立日期"
          align="center"
          width="220"
        >
        </el-table-column>
        <template v-if="dates.length > 0">
          <el-table-column
            v-for="item in dates"
            :key="labelConfig[0][item]"
            :label="labelConfig[0][item]"
            :prop="columnConfig[0][item]"
            align="center"
            width="220"
          >
          </el-table-column>
          <el-table-column
            v-for="item in dates"
            :key="labelConfig[1][item]"
            :label="labelConfig[1][item]"
            :prop="columnConfig[1][item]"
            align="center"
            width="220"
          >
          </el-table-column>
          <el-table-column
            v-for="item in dates"
            :key="labelConfig[2][item]"
            :label="labelConfig[2][item]"
            :prop="columnConfig[2][item]"
            align="center"
            width="220"
          >
          </el-table-column>
          <el-table-column
            v-for="item in dates"
            :key="labelConfig[3][item]"
            :label="labelConfig[3][item]"
            :prop="columnConfig[3][item]"
            align="center"
            width="220"
          >
          </el-table-column>
        </template>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: "SchemePosition",
  props: {
    ptfloId: {
      type: String,
      default: "",
    },
    customerSigningInfo: {
      type: Object,
      default() {
        return {};
      },
    },
    custNo: {
      type: [String, Number],
      default: "",
    },
  },
  data() {
    return {
      tableData: [],
      loading: false,
      dates: [],
      columnConfig: [
        [
          "totRetRt",
          "near3MoRetRt",
          "near6MoRetRt",
          "near1YrRetRt",
          "near2YrRetRt",
          "near3YrRetRt",
        ],
        [
          "totAnulretRt",
          "near3MoAnulretRt",
          "near6MoAnulretRt",
          "near1YrAnulretRt",
          "near2YrAnulretRt",
          "near3YrAnulretRt",
        ],
        [
          "totAnulrskRt",
          "near3MoAnulrskRt",
          "near6MoAnulrskRt",
          "near1YrAnulrskRt",
          "near2YrAnulrskRt",
          "near3YrAnulrskRt",
        ],
        [
          "totMaxWdrw",
          "near3MoMaxWdrw",
          "near6MoMaxWdrw",
          "near1YrMaxWdrw",
          "near2YrMaxWdrw",
          "near3YrMaxWdrw",
        ],
      ],
      labelConfig: [
        [
          "成立以来收益率",
          "近三月收益率",
          "近六月收益率",
          "近一年收益率",
          "近二年收益率",
          "近三年收益率",
        ],
        [
          "成立以来年化收益率",
          "近三月年化收益率",
          "近六月年化收益率",
          "近一年年化收益率",
          "近二年年化收益率",
          "近三年年化收益率",
        ],
        [
          "成立以来年化波动率",
          "近三月年化波动率",
          "近六月年化波动率",
          "近一年年化波动率",
          "近二年年化波动率",
          "近三年年化波动率",
        ],
        [
          "成立以来最大回撤率",
          "近三月最大回撤率",
          "近六月最大回撤率",
          "近一年最大回撤率",
          "近二年最大回撤率",
          "近三年最大回撤率",
        ],
      ],
    };
  },
  watch: {
    ptfloId() {
      this.getData();
    },
  },
  mounted() {
    this.getData();
  },
  methods: {
    // 成立以来必选
    changeDates(value) {
      this.dates = [...value];
    },
    async getData() {
      this.loading = true;
      await this.fetchQueryPortfolioProduct();
      await window.setTimeout(() => {
        this.fetchQueryProductIndexDetail();
      }, 3000);
      this.loading = false;
    },
    // 产品指标明细查询
    async fetchQueryProductIndexDetail() {
      const { code = 0, records = [] } = {
        code: 1,
        note: "成功",
        records: [
          {
            statcDt: "20230921",
            pdCode: "000008",
            near1MoRetRt: "-1.66%",
            near3MoRetRt: "-5.50%",
            near6MoRetRt: "-7.97%",
            thisYrRetRt: "",
            totRetRt: "70.43%",
            near1MoMaxWdrw: "-3.55%",
            near3MoMaxWdrw: "-8.43%",
            near1YrMaxWdrw: "-11.56%",
            thisYrMaxWdrw: "",
            totMaxWdrw: "-62.20%",
            thisYrSharpRt: "",
            totSharpRt: "0.00",
            near1YrRetRt: "-4.04%",
            near2YrRetRt: "-20.22%",
            near3YrRetRt: "-7.31%",
            near3MoAnulretRt: "0.99%",
            near6MoAnulretRt: "1.09%",
            near1YrAnulretRt: "2.23%",
            near2YrAnulretRt: "2.23%",
            near3YrAnulretRt: "2.23%",
            totAnulretRt: "5.20%",
            near2YrMaxWdrw: "-28.92%",
            near3YrMaxWdrw: "-30.20%",
            near6MoMaxWdrw: "-11.56%",
            near3MoAnulrskRt: "",
            near6MoAnulrskRt: "",
            near1YrAnulrskRt: "",
            near2YrAnulrskRt: "",
            near3YrAnulrskRt: "",
            totAnulrskRt: "",
          },
          {
            statcDt: "20230921",
            pdCode: "000009",
            near1MoRetRt: "0.14%",
            near3MoRetRt: "0.44%",
            near6MoRetRt: "0.93%",
            thisYrRetRt: "",
            totRetRt: "37.84%",
            near1MoMaxWdrw: "0.00%",
            near3MoMaxWdrw: "0.00%",
            near1YrMaxWdrw: "0.00%",
            thisYrMaxWdrw: "",
            totMaxWdrw: "0.00%",
            thisYrSharpRt: "",
            totSharpRt: "0.01",
            near1YrRetRt: "1.84%",
            near2YrRetRt: "3.77%",
            near3YrRetRt: "6.06%",
            near3MoAnulretRt: "0.99%",
            near6MoAnulretRt: "1.09%",
            near1YrAnulretRt: "2.23%",
            near2YrAnulretRt: "2.23%",
            near3YrAnulretRt: "2.23%",
            totAnulretRt: "3.09%",
            near2YrMaxWdrw: "0.00%",
            near3YrMaxWdrw: "0.00%",
            near6MoMaxWdrw: "0.00%",
            near3MoAnulrskRt: "",
            near6MoAnulrskRt: "",
            near1YrAnulrskRt: "",
            near2YrAnulrskRt: "",
            near3YrAnulrskRt: "",
            totAnulrskRt: "",
          },
          {
            statcDt: "20230921",
            pdCode: "000011",
            near1MoRetRt: "-2.28%",
            near3MoRetRt: "-5.50%",
            near6MoRetRt: "-8.08%",
            thisYrRetRt: "",
            totRetRt: "2997.95%",
            near1MoMaxWdrw: "-4.75%",
            near3MoMaxWdrw: "-8.26%",
            near1YrMaxWdrw: "-14.74%",
            thisYrMaxWdrw: "",
            totMaxWdrw: "-49.54%",
            thisYrSharpRt: "",
            totSharpRt: "0.00",
            near1YrRetRt: "-8.81%",
            near2YrRetRt: "-23.31%",
            near3YrRetRt: "-12.78%",
            near3MoAnulretRt: "0.99%",
            near6MoAnulretRt: "1.09%",
            near1YrAnulretRt: "2.23%",
            near2YrAnulretRt: "2.23%",
            near3YrAnulretRt: "2.23%",
            totAnulretRt: "19.66%",
            near2YrMaxWdrw: "-29.20%",
            near3YrMaxWdrw: "-33.49%",
            near6MoMaxWdrw: "-10.64%",
            near3MoAnulrskRt: "",
            near6MoAnulrskRt: "",
            near1YrAnulrskRt: "",
            near2YrAnulrskRt: "",
            near3YrAnulrskRt: "",
            totAnulrskRt: "",
          },
          {
            statcDt: "20230921",
            pdCode: "000033",
            near1MoRetRt: "-0.36%",
            near3MoRetRt: "0.65%",
            near6MoRetRt: "2.19%",
            thisYrRetRt: "",
            totRetRt: "52.45%",
            near1MoMaxWdrw: "-0.68%",
            near3MoMaxWdrw: "-0.68%",
            near1YrMaxWdrw: "-2.46%",
            thisYrMaxWdrw: "",
            totMaxWdrw: "-5.17%",
            thisYrSharpRt: "",
            totSharpRt: "0.00",
            near1YrRetRt: "1.52%",
            near2YrRetRt: "5.91%",
            near3YrRetRt: "10.05%",
            near3MoAnulretRt: "0.99%",
            near6MoAnulretRt: "1.09%",
            near1YrAnulretRt: "2.23%",
            near2YrAnulretRt: "2.23%",
            near3YrAnulretRt: "2.23%",
            totAnulretRt: "4.13%",
            near2YrMaxWdrw: "-2.46%",
            near3YrMaxWdrw: "-2.46%",
            near6MoMaxWdrw: "-0.68%",
            near3MoAnulrskRt: "",
            near6MoAnulrskRt: "",
            near1YrAnulrskRt: "",
            near2YrAnulrskRt: "",
            near3YrAnulrskRt: "",
            totAnulrskRt: "",
          },
        ],
        hasrecordset: 1,
        total: 4,
      };
      if (code > 0 && records.length > 0) {
        const newTableData = [];
        this.tableData.forEach((v, i) => {
          const obj = records.find((item) => v.pdCode === item.pdCode);
          if (obj) {
            newTableData[i] = Object.assign(v, obj);
          } else {
            newTableData[i] = v;
          }
          // newTableData[i] = Object.assign(this.tableData[i], records[i]);
        });
        this.tableData = newTableData;
        this.changeDates(["0"]);
      }
    },
    // 查询组合产品列表
    async fetchQueryPortfolioProduct() {
      if (this.ptfloId !== "-1") {
        const { code = 0, records = [] } = {
          code: 1,
          note: "SELECT T.*, CONCAT(format(DMND.EXP_INVST_AMT * T.AST_RTO / 100, 2), '万元')  AST_AMT FROM (SELECT PTFLO_INF.PTFLO_ID AS PID, PD_INF.PD_CODE AS PD_CODE,\r\n\t\t\t\t\t\t\t\t\t\t\t\t PD_INF.PD_NM AS PD_NM, \r\n\t\t\t\t\t\t\t\t\t\t\t\t ROUND(PTFLO_PD.AST_RTO, 4) AS AST_RTO, \r\n\t\t\t\t\t\t\t\t\t\t\t\t ROUND(PTFLO_PD.CUR_AST_RTO, 4) AS CUR_AST_RTO,\r\n\t\t\t\t\t\t\t\t\t\t\t\t PD_INF.AST_CL_ID AS AST_CL_ID,\r\n\t\t\t\t\t\t\t\t\t\t\t\t (SELECT L.NOTE FROM LIVEBOS.TXTDM L WHERE PD_INF.AST_CL_ID=L.IBM AND L.FLDM='WAS_INVST_STY') AS AST_CL_NM,\r\n\t\t\t\t\t\t\t\t\t\t\t\t PD_INF.AST_TP AS AST_TP,\r\n\t\t\t\t\t\t\t\t\t\t\t\t (SELECT L.NOTE FROM livebos.txtdm L WHERE PD_INF.AST_TP=L.IBM AND L.FLDM='WAS_AST_TP') AS AST_TP_NM,\r\n\t\t\t\t\t\t\t\t\t\t\t\t PD_INF.RSK_LVL AS RSK_LVL,\r\n\t\t\t\t\t\t\t\t\t\t\t\t PD_INF.ESTB_DT AS ESTB_DT,\r\n\t\t\t\t\t\t\t\t\t\t\t\t (select group_concat(F_INFO_FUNDMANAGER) as F_INFO_FUNDMANAGER from ardb.t_ods_t70_ChinaMutualFundManager c where   left(c.F_INFO_WINDCODE,6)= PD_INF.PD_CODE and F_INFO_MANAGER_LEAVEDATE is null group by F_INFO_WINDCODE) AS FUND_MGR_NM,\r\n\t\t\t\t\t\t\t\t\t\t\t\t PD_INF.FUND_CO_NM AS FUND_CO_NM,\r\n\t\t\t\t\t\t\t\t\t\t\t\t PD_INF.FUND_ST_DESC AS FUND_ST,\r\n\t\t\t\t\t\t\t\t\t\t\t\t \t\t\t\t\t\t\t(SELECT\t\tCONCAT('[',(SELECT GROUP_CONCAT((JSON_OBJECT( 'PRTY',PTFLO_PD_ALT_POOL.PRTY,'PD_NM',PD_INF.PD_NM,'PD_CODE',PTFLO_PD_ALT_POOL.ALT_PD_CODE,'AST_CL_NM',(SELECT L.NOTE FROM livebos.txtdm L WHERE PD_INF.AST_CL_ID=L.IBM AND L.FLDM='WAS_INVST_STY'),'AST_TP_NM',(SELECT L.NOTE FROM livebos.txtdm L WHERE PD_INF.AST_TP=L.IBM AND L.FLDM='WAS_AST_TP'),'RSK_LVL_NM',(SELECT L.NOTE FROM livebos.txtdm L WHERE PD_INF.RSK_LVL=L.IBM AND L.FLDM='WAS_RSK_LVL'))) ORDER BY  PTFLO_PD_ALT_POOL.PRTY)  FROM TWAS_PD_INF PD_INF  ,TWAS_PTFLO_PD_ALT_POOL_PERS PTFLO_PD_ALT_POOL WHERE PTFLO_PD_ALT_POOL.ALT_PD_CODE=PD_INF.PD_CODE\r\n\t\t\t\t\t\t\t\t\t\tAND PTFLO_PD_ALT_POOL.PTFLO_ID=PTFLO_INF.PTFLO_ID AND PTFLO_PD_ALT_POOL.PD_CODE=PTFLO_PD.PD_CODE),']') FROM DUAL) AS PTFLO_PD_ALT,\r\n\t\t\t\t\t\t\t\t\t\t(SELECT L.NOTE FROM livebos.txtdm L WHERE PD_INF.RSK_LVL=L.IBM AND L.FLDM='WAS_RSK_LVL')    AS RSK_LVL_NM\r\n\t\t\t\t\t\t\t\t\t  FROM TWAS_PD_INF PD_INF,TWAS_PTFLO_INF_PERS PTFLO_INF left join TWAS_PTFLO_PD_PERS PTFLO_PD ON (PTFLO_INF.PTFLO_ID=PTFLO_PD.PTFLO_ID) \r\n\t\t\t\t\t\t\t\t\t  WHERE left(PTFLO_PD.PD_CODE,6)=left(PD_INF.PD_CODE,6) AND 1 = 1  AND PTFLO_PD.PTFLO_ID= 1904) T, \r\n\t\t\tTWAS_PTFLO_INF_PERS PTFLO_INF, TWAS_CUST_DMND DMND \r\n\t\t\tWHERE T.PID = PTFLO_INF.PTFLO_ID AND PTFLO_INF.CUST_ARG_ID = DMND.CUST_ARG_ID ",
          records: [
            {
              pdCode: "000011",
              pdNm: "华夏大盘精选A",
              astRto: "20.0000",
              curAstRto: "20.0400",
              astClId: "4",
              astClNm: "权益类",
              astTp: "",
              astTpNm: "",
              rskLvl: "3",
              estbDt: "2004-08-11",
              fundMgrNm: "陈伟彦",
              fundCoNm: "华夏基金",
              fundSt: "",
              ptfloPdAlt: "",
              rskLvlNm: "中风险",
              astAmt: "0.20万元",
            },
            {
              pdCode: "000008",
              pdNm: "嘉实中证500ETF联接A",
              astRto: "40.0000",
              curAstRto: "50.0300",
              astClId: "4",
              astClNm: "权益类",
              astTp: "",
              astTpNm: "",
              rskLvl: "3",
              estbDt: "2013-03-22",
              fundMgrNm: "李直,何如",
              fundCoNm: "嘉实基金",
              fundSt: "",
              ptfloPdAlt: "",
              rskLvlNm: "中风险",
              astAmt: "0.40万元",
            },
            {
              pdCode: "000033",
              pdNm: "易方达信用债C",
              astRto: "30.0000",
              curAstRto: "29.9300",
              astClId: "8",
              astClNm: "",
              astTp: "",
              astTpNm: "",
              rskLvl: "2",
              estbDt: "2013-04-24",
              fundMgrNm: "纪玲云,胡剑",
              fundCoNm: "易方达基金",
              fundSt: "",
              ptfloPdAlt: "",
              rskLvlNm: "中低风险",
              astAmt: "0.30万元",
            },
            {
              pdCode: "000009",
              pdNm: "易方达天天A",
              astRto: "10.0000",
              curAstRto: "0.0000",
              astClId: "9",
              astClNm: "",
              astTp: "",
              astTpNm: "",
              rskLvl: "1",
              estbDt: "2013-03-04",
              fundMgrNm: "石大怿,刘朝阳",
              fundCoNm: "易方达基金",
              fundSt: "",
              ptfloPdAlt: "",
              rskLvlNm: "低风险",
              astAmt: "0.10万元",
            },
          ],
        };
        if (code > 0) {
          this.tableData = records.map((item) => {
            return item;
          });
        }
      }
      this.changeDates(["0"]);
    },
    getCellStyle({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        return { borderRight: "1px solid #EDEDED" };
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.options {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  //margin-top: -4.42rem;
}
.noData {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
